package com.atwork.wuhua.mvp.presenter;

import com.atwork.wuhua.base.BasePresenter;
import com.atwork.wuhua.base.BaseReq;
import com.atwork.wuhua.base.MyApplication;
import com.atwork.wuhua.bean.FieldDetailListBean;
import com.atwork.wuhua.bean.FieldDetialBean;
import com.atwork.wuhua.mvp.Callback;
import com.atwork.wuhua.mvp.DataModel;
import com.atwork.wuhua.mvp.Token;
import com.atwork.wuhua.mvp.view.ISubLaunDetailActivity;
import com.atwork.wuhua.utils.LogUtils;

public class SubLaunDetailPresenter extends BasePresenter<ISubLaunDetailActivity> {
    /**
     * GET /site/detail 获取场馆详情
     *
     * @param id
     */
    public void getDetail(final String id) {
        BaseReq req = new BaseReq();
        req.setKey("id", id);
        DataModel.request(Token.API_FIELDDETAIL)
                .params(req)
                .execute(new Callback<FieldDetialBean>() {

                    public void onSuccess(String msg, FieldDetialBean data) {
                        getView().getFieldDetail(data);
                        getDetailList(id);
                    }

                    @Override
                    public void onFailure(String msg) {
                        hideLoading();
                    }

                    @Override
                    public void onError() {

                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }


    /**
     * GET /site/field 获取场馆训练场列表
     *
     * @param id
     */
    public void getDetailList(String id) {
        BaseReq req = new BaseReq();
        req.setKey("id", id);
        DataModel.request(Token.API_FIELDDETAIL_LIST)
                .params(req)
                .execute(new Callback<FieldDetailListBean>() {

                    public void onSuccess(String msg, FieldDetailListBean data) {
                        getView().getFieldDetailList(data);
                        hideLoading();
                    }

                    @Override
                    public void onFailure(String msg) {
                        hideLoading();
                    }

                    @Override
                    public void onError() {

                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }


    public void bespeak(final String site_id, final String field_id, String bespeak_time, int limit_count) {
        if (bespeak_time.length() == 0) {
            showToast("请选择约战的时间");
            return;
        }
        if (limit_count == 0) {
            showToast("请选择约战的人数");
            return;
        }
        showLoading();
        BaseReq req = new BaseReq();
        req.setKey("uuid", MyApplication.UUID);
        req.setKey("site_id", site_id);
        req.setKey("field_id", field_id);
        req.setKey("bespeak_time", bespeak_time);
        req.setKey("type", "2");
        req.setKey("limit_count", limit_count + "");
        LogUtils.e("发起约战==》" + req.getString());
        DataModel.request(Token.API_FIELD_BESPEAK)
                .params(req)
                .execute(new Callback<String>() {

                    public void onSuccess(String msg, String data) {
                        showToast(msg);
                        hideLoading();
                        getView().bespeakResult();
                    }

                    @Override
                    public void onFailure(String msg) {
                        hideLoading();
                    }

                    @Override
                    public void onError() {

                    }

                    @Override
                    public void onComplete() {

                    }


                });

    }
}
